package com.wwy;

import com.wwy.domain.FiltrationTimeEntiry;
import com.wwy.domain.RssiEntity;
import com.wwy.service.FiltrationTimeService;
import com.wwy.service.RssiService;
import org.springframework.context.ApplicationContext;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Author: wwy
 * @Date: 2020/8/19 16:47
 */
public class FiltrationTimeDialog extends JDialog implements ActionListener {
    public static ApplicationContext applicationContext;
    public static FiltrationTimeEntiry filtrationTimeEntiry = new FiltrationTimeEntiry();
    JLabel lableTitle;
    JLabel lableTitle1;
    public JTextField lableText;
    public JTextField lableText1;
    JButton quitButton;
    JButton saveButton;
    public FiltrationTimeDialog(JFrame F,String s) {
        super(F,s,true);//模态
        this.setBounds(200, 200, 700, 540);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(2,1));
        panel.setSize(700,540);

        JPanel topPanel = new JPanel();
        topPanel.setVisible(true);
        topPanel.setLayout(new FlowLayout());
        panel.add(topPanel);
        lableTitle = new JLabel("时间范围");
        lableTitle1 = new JLabel("秒");
        lableText = new JTextField("",10);
        lableText.setText(filtrationTimeEntiry.getTime()+"");
        lableText.setEditable(true);
        topPanel.add(lableTitle);
        topPanel.add(lableText);
        topPanel.add(lableTitle1);
        JPanel top1Panel = new JPanel();
        top1Panel.setVisible(true);
        top1Panel.setLayout(new FlowLayout());
        JPanel top2Panel = new JPanel();
        top2Panel.setVisible(true);
        top2Panel.setLayout(new FlowLayout());
        quitButton = new JButton("取消");
        quitButton.setActionCommand("quit");
        quitButton.addActionListener(this);
        saveButton = new JButton("确定");
        saveButton.setActionCommand("save");
        saveButton.addActionListener(this);
        top2Panel.add(quitButton);
        top2Panel.add(saveButton);
        panel.add(top2Panel);
        panel.setVisible(true);
        setModal(false);
        this.setContentPane(panel);
        this.pack();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()){
            case "quit":
                System.out.println("执行退出");
                dispose();
                break;
            case "save":
                System.out.println("执行保存");
                //调用新增代码
                FiltrationTimeService filtrationTimeService = applicationContext.getBean(FiltrationTimeService.class);
                FiltrationTimeEntiry filtrationTimeEntiry1 = new FiltrationTimeEntiry();
                filtrationTimeEntiry1.setTime(Integer.parseInt(lableText.getText()));
                filtrationTimeEntiry = filtrationTimeEntiry1;
                filtrationTimeService.save(filtrationTimeEntiry1);
                dispose();
                break;
        }
    }
}
